<?php
/**
 * 牌局人数统计（去重）
 * @author chenjinle
 * @date 2017/6/20
 * php ../script.php request/CleanCodeHandler
 */

class CleanCodeHandler extends ScriptBase 
{
	/**
	 * 逻辑代码
	 */
	public function logic()
	{
		set_time_limit(0);
		$db = $this->mysql('game');
		$redis = $this->redis('user_info');

		$file = __DIR__ . "/../data/logs/cleancode_".date("YmdHi").".log";

		$this->writeFile($file, "----------------------\n", 'ab');

		// 清除绑定码
		$bindUids = array(251521,247350,105093,251062,162077,239416,243843,243874,264105,240748,244822,244818,245325,157812,122126,260073,248320,267311,245951,246646,250884,136020,256596,268446,242495,242537,208353,199186,262836,263029,262775,264169,268615,270646,271165,248315,248318,130024,237514,188710,249303,257513,259351,264765,247267,247275,247291,247290,247300,247311,247327,240832,245865,257064,203536,231292,194798,247336,250599,258082,205986,262893,267343,234656,253900,254509,243343,240308,243373,252121,256085,261871,267023,257707,232009,235267,260485,260722,258009,166591,255982,139629,270356,154642,238856,263945,238240,238247,162348,243406,243132,263522,269535,240087,241276,241094,239872,264504,242591,218909,244188,244728,244750,244786,251989,246482,248605,247346,256050,247279,269127,247970,188610,253133,138302,271440,253782,255013,255075,255085,255382,262971,258326,245443,189486,259281,261062,262575,262554,263128,263385,266112,266454,267488,264088,260987);
		if ($bindUids) {
			foreach ($bindUids as $uid) {
				$row = $db->findRow('d_user_promo_codes', ['uid'=>$uid]);
				// var_dump($row, $uid);exit;
				$flg = (int)$db->update('d_user_promo_codes', ['promo_code'=>0], ['uid'=>$uid]);
				// 清理缓存
				$redis->hdel("U:{$uid}", 'promo_code');
				// 写日志备份
				$logMsg = sprintf("1|{$uid}|%s|%s|%s\n", $row['agent_code'], $row['promo_code'], $flg);
				echo $logMsg;
				$this->writeFile($file, $logMsg, 'ab');
			}
		}


		// 清除代理
		$agents = array(183079,200957,264166,249505,244911,205986,263356,131775,233482,103456,263076,160823,117866,262825,106690,243596,262630,262521,231447,187935,229060,203050,100548,261963,227443,259500,132195,106564,253317,230929,215533,110619,229577,260963,259484,218082,260987,257474,224162,131571,260470,234215,178290,194340,260282,260048,184557,137875,254513,152425,129001,180308,228218,122126,249034,259271,233566,259031,254992,166138,247279,167532,258415,230902,229124,257251,136912,143242,137120,200781,171182,256982,256715,217044,149186,256609,202416,248979,202003,255931,256419,244150,170124,239490,247432,213787,239829,229720,209900,255602,213864,160029,203060,232266,240758,255212,252165,255064,100400,245392,255005,172030,123856,119407,226278,235055,104375,229108,104397,244833,104380,104376,109586,193327,253588,253559,143581,232196,121288,229205,227718,199507,174146,245036,224664,242176,213619,179605,251983,251305,251840,251184,237454,118286,230345,251523,151360,251412,101536,251356,239877,239914,250941,250879,100130,169953,205637,109818,250188,213236,250364,122904,198438,112550,250033,104786,249853,249738,235939,142889,172137,186672,248560,247938,156616,193062,242448,188966,247154,247467,129463,247245,184097,247207,247195,203102,246117,240644,215748,217568,246521,137862,205572,203734,173325,171784,239406,138264,182905,113369,245442,176213,244189,241845,245144,244980,200745,244690,160764,103821,244689,163525,119893,230877,217663,225404,113160,244175,221298,243996,208086,108356,161314,228969,238769,223242,243048,239166,242800,238737,118133,242730,240920,192810,242585,158429,204021,210615,153978,241976,219692,221577,187156,240941,241567,241107,240372,241200,200827,241100,241051,240967,174106,240843,237837,189514,237793,106406,240460,239721,186258,180492,239839,239808,124977,101457,135225,129032,239325,238684,217907,237152,223798,238238,102648,238053,172970,218487,162722,107646,237630,237472,136590,237085,228559);
		if ($agents) {
			foreach ($agents as $uid) {
				$row = $db->findRow('d_user_promo_codes', ['uid'=>$uid]);
				$flg = (int)$db->update('d_user_promo_codes', ['agent_code'=>0], ['uid'=>$uid]);
				// 清理缓存
				$redis->hdel("U:{$uid}", 'agent_code');
				// 写日志备份
				$logMsg = sprintf("2|{$uid}|%s|%s|%s\n", $row['agent_code'], $row['promo_code'], $flg);
				echo $logMsg;
				$this->writeFile($file, $logMsg, 'ab');
			}
		}
	}
}